package org.ourgrid.acceptance.util.discoveryservice;

import java.util.LinkedList;
import java.util.List;

import org.easymock.classextension.EasyMock;
import org.ourgrid.acceptance.util.DiscoveryServiceAcceptanceUtil;
import org.ourgrid.common.interfaces.status.DiscoveryServiceStatusProviderClient;
import org.ourgrid.discoveryservice.DiscoveryServiceComponent;
import org.ourgrid.discoveryservice.communication.receiver.DiscoveryServiceComponentReceiver;
import org.ourgrid.matchers.DiscoveryServiceCompleteStatusMatcher;

import br.edu.ufcg.lsd.commune.container.ObjectDeployment;
import br.edu.ufcg.lsd.commune.context.ModuleContext;
import br.edu.ufcg.lsd.commune.identification.ContainerID;
import br.edu.ufcg.lsd.commune.identification.DeploymentID;
import br.edu.ufcg.lsd.commune.testinfra.AcceptanceTestUtil;

public class Req_504_Util extends DiscoveryServiceAcceptanceUtil {
	
	public Req_504_Util(ModuleContext context) {
		super(context);
	}
	
	public void getEmptyCompleteStatus(DiscoveryServiceComponent component) {
		getCompleteStatus(component, new LinkedList<String>());
	}
	
	public void getCompleteStatus(DiscoveryServiceComponent component, List<String> connectedPeers) {
		DiscoveryServiceComponentReceiver dscc = (DiscoveryServiceComponentReceiver) getDiscoveryServiceControl(component);
		ObjectDeployment dsOD = getDiscoveryServiceControlDeployment(component);
		DiscoveryServiceStatusProviderClient statusProviderMock = EasyMock.createMock(DiscoveryServiceStatusProviderClient.class);
		
		statusProviderMock.hereIsCompleteStatus(DiscoveryServiceCompleteStatusMatcher.eqMatcher(connectedPeers));
		
		EasyMock.replay(statusProviderMock);
		
		DeploymentID deploymentID = new DeploymentID(new ContainerID("dsClient", "dsServer", "peer", "peerPK"), "peer");
		AcceptanceTestUtil.publishTestObject(component, deploymentID, statusProviderMock,
				DiscoveryServiceStatusProviderClient.class);
		
		AcceptanceTestUtil.setExecutionContext(component, dsOD, deploymentID);
		
		dscc.getCompleteStatus(statusProviderMock);
		
		EasyMock.verify(statusProviderMock);
	}

	
}
